package two.chapter_3.c3_5;

import edu.princeton.cs.algs4.In;
import edu.princeton.cs.algs4.StdIn;
import edu.princeton.cs.algs4.StdOut;
import two.chapter_3.c3_1.BST;
import two.chapter_3.c3_1.ST;

import java.io.File;

public class FileIndex {

    public static void main(String args[]){
        ST<String,Set<File>> st=new BST<>();
        String files[]={"/Users/wind/Desktop/filelevel/1.txt",
                "/Users/wind/Desktop/filelevel/2.txt",
                "/Users/wind/Desktop/filelevel/3.txt"};
        for (String filename:files){
            File file=new File(filename);
            In in=new In(file);
            while (!in.isEmpty()){
                String word=in.readString();
                if (!st.contains(word)) st.put(word,new HashSet<File>());
                Set<File> set=st.get(word);
                set.add(file);
            }
        }
        while (!StdIn.isEmpty()){
            String query=StdIn.readString();
            if (st.contains(query)){
                for (File file:st.get(query)){
                    StdOut.println(" "+file.getName());
                }
            }
        }
    }
}
